<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<c:set var="ctx" value="${pageContext.request.contextPath}"/>

<ul class="breadcrumb panel">
    <li><a href="javascript:backMainFun();"><i class="fa fa-home"></i> 首页</a></li>
    <li><a href="javascript:loadFun('/org/toOrgIndex');">组织机构</a></li>
    <li class="active">新增组织</li>
</ul>

<div class="panel">
    <header class="panel-heading">
        新增组织
    </header>
    <div class="panel-body">
        <form action="${ctx}/user/doSave" name="userForm" id="userForm" method="post" class="form-horizontal">
            <input type="hidden" id="org_id" value="${org.org_id}"/>
            <input type="hidden" id="parent_id" value="${org.parent_id}"/>
            <div class="form-group">
                <label for="name" class="col-sm-2 control-label must">组织简称</label>
                <div class="col-sm-8">
                    <input type="text" class="form-control" id="name" name="name" placeholder="请输入组织简称" value="${org.name}">
                </div>
            </div>
            <div class="form-group">
                <label for="full_name" class="col-sm-2 control-label must">组织全称</label>
                <div class="col-sm-8">
                    <input type="text" class="form-control" id="full_name" name="full_name" placeholder="请输入组织全称" value="${org.full_name}">
                </div>
            </div>
            <div class="form-group">
                <label for="sort_no" class="col-sm-2 control-label must">顺序</label>
                <div class="col-sm-8">
                    <input type="number" class="form-control" id="sort_no" name="sort_no" placeholder="请输入组织顺序" value="${org.sort_no}">
                </div>
            </div>
            <div class="row">
                <div class="col-xs-10">
                    <button type="button" class="btn btn-primary pull-right" id="subBtn"><i
                            class="glyphicon glyphicon-saved"></i> 保存
                    </button>
                    <button type="button" class="btn btn-default pull-right marR" onclick="backFun()"><i
                            class="glyphicon glyphicon-chevron-left"></i> 返回
                    </button>
                </div>
            </div>

        </form>
    </div>
</div>



<script>
    function backFun() {
        loadFun("/org/toOrgIndex");
    }
    $('#full_name').blur(function () {
        if ($('#full_name').val() != false) {
            $.post("${ctx}/org/checkName",
                    {
                        org_id:$('#org_id').val(),
                        name: $('#full_name').val(),
                        parent_id: $('#parent_id').val(),
                    }
                    , function (data) {
                        if (!data.valid) {
                            zAlert("上级组织下已存在该名称，请重新填写!");
                            $('#full_name').focus();
                            $('#subBtn').attr("disabled",true);
                        }else{
                            $('#subBtn').attr("disabled",false);
                        }
                    });
        }
    });

    $('#subBtn').click(function () {
        if ($('#name').val() == false) {
            zAlert('组织简称不能为空')
            return false;
        }else if ($('#full_name').val() == false) {
            zAlert('组织全称不能为空')
            return false;
        }  else if ($('#sort_no').val() == false) {
            zAlert('组织顺序不能为空')
            return false;
        } else {
            $.ajax({
                url: "${ctx}/org/save",
                type: 'post',
                data: {
                    org_id:$('#org_id').val(),
                    name: $('#name').val(),
                    full_name: $('#full_name').val(),
                    sort_no:$('#sort_no').val()
                },
                success: function (data) {
                    if (data.success) {
                        zAlert(data.msg);
                        setTimeout(function () {
                            loadFun("/org/toOrgIndex");
                        }, 1000);
                    } else {
                        zAlert(data.msg);
                    }
                }
            })
        }
    });

</script>

